import { _decorator, Component, director, Node, NodeEventType, tween, Vec3 } from 'cc';
import { loadPool } from '../res/loadPool';
import { bgmName, emits } from '../data/enmus';
import { audioTool } from '../untils/audioTool';
import { wxAd } from '../AD/wxAd';
import { gameConfig } from '../data/gameConfig';
import { adMgr } from '../AD/adMgr';
const { ccclass, property } = _decorator;

@ccclass('setting')
export class setting extends Component {
    @property(Node) back: Node;
    private popUI: Node;
    protected onEnable(): void {
        this.init()
    }
    init() {
        director.on(emits.backIsShow, this.backIsShow, this)
        let close = this.node.getChildByPath('popUI/close')
        close.on(NodeEventType.TOUCH_START, this.closeBtn, this)
        // 进场动画
        this.popUI = this.node.getChildByName('popUI')
        this.popUI.setScale(0, 0)
        tween(this.popUI).to(0.2, { scale: new Vec3(1, 1, 1) }).by(0.06, { scale: new Vec3(0.2, 0.2, 1) }).by(0.05, { scale: new Vec3(-0.2, -0.2, 1) }).start()
    }
    protected onDestroy(): void {
        director.off(emits.backIsShow, this.backIsShow, this)
    }
    // 关闭弹窗
    closeBtn() {
        // 播放音效
        audioTool.ins.playSound(bgmName.sound_btn)
        // 出场动画
        tween(this.popUI).by(0.06, { scale: new Vec3(0.2, 0.2, 1) }).by(0.05, { scale: new Vec3(-0.2, -0.2, 1) }).to(0.02, { scale: new Vec3(1.1, 1.1, 1) }).to(0.1, { scale: new Vec3(0, 0, 1) }).call(() => {
            loadPool.ins.huiShouNode(this.node)
        }).start()
    }
    // 返回首页
    backBtn() {
        audioTool.ins.stopMusic()
        loadPool.ins.huiShouNode(this.node)
        director.loadScene('home')
    }
    backIsShow(val: number) {
        if (val == 1) {
            this.back.active = true
        } else {
            this.back.active = false
        }
    }
}
